import requests
import os

# 注意更换为内网穿透后的地址
base_url = "http://127.0.0.1:5000/predict"

# 测试文件上传
def test_file_upload():
    file_path = "img/bianmu.jpg"  # 替换为你的测试图片路径
    if not os.path.exists(file_path):
        print(f"File '{file_path}' does not exist.")
        return

    with open(file_path, "rb") as file:
        files = {"image": file}
        response = requests.post(base_url, files=files)

    print("Testing file upload:")
    print("Response status code:", response.status_code)
    print("Response text:", response.text)

# 测试通过 URL 下载图片
def test_image_url():
    image_url = "https://ts1.tc.mm.bing.net/th/id/OIP-C.98T3nKgzDctVW8gIQHHdHAHaJ3?w=160&h=211&c=8&rs=1&qlt=90&o=6&pid=3.1&rm=2"  # 替换为你的测试图片 URL
    data = {"image_url": image_url}
    response = requests.post(base_url, data=data)

    print("Testing image URL:")
    print("Response status code:", response.status_code)
    print("Response text:", response.text)

if __name__ == "__main__":
    print("Starting tests...")
    test_file_upload()
    test_image_url()